(function($){
	/********HQuery********/
	var HY=function(o){
		return new HY.prototype.init(o);
	}
	
	
	window.$HY = HY;
	
	HY.prototype ={
		v: 'v1',
		init : function(o){
			this.input = o;
		},
		say : function(){
		log(this.input);
		},
		setV:function(n){
			this.v = n;
		}
	};
	HY.prototype.input2 = 'input2';
	 HY.prototype.init.prototype = HY.prototype;

	/********HQuery********/

	DT={
		v:'DT2.0',
		init :function(o){
			this.input = o;
		},
		say : function(){
			log(this.input);
		},
		setV:function(n){
			this.v = n;
		},
		getIns :function(o){
			
			return new DT.init(o);
		}
	}
	DT.init.prototype = DT;
	
})(jQuery);
/**
 * 待办事项
 *
 	调用(可传数组)：

 	var todo = TD().add({
 		msgId:'' 		//选填，用来控制修改、删除,相同的视为修改
 		,title :'' 	//展示信息
 		,expireTime:'' //失效时间，不传则永不失效
 		,url:''			//跳转url
 		,openType:'POP/TAB'	//弹框或者页签打开方式
 		,openFunc:''	//自定义打开方法
 		,popInit://loadIframe 的各项参数加上 {customOption:{}} 
 	});
 *	todo.mod({...});
 	todo.del(msgId);
 *	todo.shift();
 *  todo.pull();
 *
 */
(function($){
	var _isArray = Array.isArray;
	var _popImp = Nebula.UI.Dialog;

	var tdStr = Nebula.ResMgr.getString('UAD_TODO');
	var spId = 1;
	var todo = function(o){
		return new todo.prototype.init(o);
	};
	var dataSrc={};
	todo.prototype ={
		init : function(o){
			this.insId = 'TD_'+spId++;
			if(o && o.id){
				window[o.id] = this;
			}
			//只提供控制自己的消息方法
			dataSrc[this.insId] = {};
			dataSrc[this.insId]._msgArr = [];
		}
		,add : function(o){
			if(!o){
				return;
			}
			if(_isArray(o)){
				o.forEach(this.add);
				return;
			}
			if(!o.msgId){
				o.msgId = this.insId + '_M_'+spId++;
			}
			dataSrc[this.insId][o.msgId]=o;
			dataSrc[this.insId]._msgArr.push(o);
			return this;
		}
		,mod : function(o){
			if(!o){
				return;
			}
			if(_isArray(o)){
				o.forEach(this.mod);
				return;
			}
			if(!o.msgId || !dataSrc[this.insId][o.msgId]){
				//防止增加错误数据
				return ;
			}
			dataSrc[this.insId][o.msgId]=o;
			return this;
		}
		,del : function(msgId){
			if(!msgId){
				return;
			}
			if(_isArray(msgId)){
				msgId.forEach(this.del);
				return;
			}
			if(msgId =='*'){
				dataSrc[this.insId]={};
				dataSrc[this.insId]._msgArr = [];
			}
			else{
				//不单个删除索引，遍历的时候判断是否存在
				delete dataSrc[this.insId][msgId];
			}
			return this;
		}
		,shift : function(){
			var myData = dataSrc[this.insId];
			var msgId = '';
			while(myData._msgArr.length && !((msgId = myData._msgArr.shift().msgId) in myData));
			if(msgId){
				delete myData[msgId];
			}
			return this;
		}
		,pull : function(){
			var myData = dataSrc[this.insId];
			var msgId = '';
			while(myData._msgArr.length && !((msgId = myData._msgArr.pull().msgId) in myData));
			if(msgId){
				delete myData[msgId];
			}
			return this;
		}
		,open : function(msgId){
			var myData = dataSrc[this.insId];
			var msgObj = myData[msgId];
			if(msgObj.openFunc){
				msgObj.openFunc(msgObj);
			}
			else{
				if(msgObj.openType && msgObj.url){
					this['open'+msgObj.openType](msgObj);
				}
			}
		}
		,openPOP : function(msgObj){
			var popInit = msgObj.popInit;
			popInit.openUrl = popInit.openUrl|| msgObj.url;
			popInit.title = popInit.title || msgObj.title;
			var pop = new _popImp();
			var buttons = {};
			buttons[$.jqueryUI.dialog.confirmButton] = function() {
				pop.iframe.okOnClick();
			};
			buttons[$.jqueryUI.dialog.confirmButton] = function() {
				pop.close();
			};
			popInit = $.extend({
				title : tdStr,
				width : 700,
				height : 450,
				destroyWhenClose : true	,
				modal:true,
				buttons:buttons
			},popInit);
			pop.loadIframe(popInit.url, popInit);
			if(popInit.customOption){
				pop.setInitValue(popInit.customOption);
			}
		}
		,openTAB : function(msgObj){
			window.top.openMenu("TD_" + msgObj.msgId, msgObj.openTitle, msgObj.url);
		}
	}
	
	todo.prototype.init.prototype = todo.prototype;
	window.TD = todo;
})(jQuery);
